$namespace("gdgs.ndp.gridbar");

gdgs.ndp.gridbar.showCriteriaBuilder=function(view, gridId){
	view.$gridId =gridId;
	var dialog = view.get('#dialogcriteria'+gridId);
	var grid  = view.get('#'+gridId);
	var ds = grid.get('dataSet');
	if(!dialog){
		var criter =new dorado.widget.CriteriaBuilder({
			dataType:ds.get('dataType'),
			id:"criteria_"+gridId,
			listener:{
				"onReady":function(self,arg){
					var defaultCriteria =grid.$_gridBar.defaultCriteria;
					if(defaultCriteria){
						self.set("criteria",defaultCriteria);
					}
					var ordersControl = self._ordersControl;
					ordersControl.__doOnBlur = ordersControl.doOnBlur;
					ordersControl.doOnBlur = function(){
						// this.__doOnBlur();
					};
				}
			}
		});
		dialog = new dorado.widget.Dialog({
		  		id:'dialogcriteria'+gridId,
				width:800,
				height:400,
				caption:'\u81EA\u5B9A\u4E49\u67E5\u8BE2',
				center:true,
				modal:true,
				maximizeable:true,
				closeable:true,
				maximizeable:false,
				closeAction:"hide",
				listener:{
					onHide:function(self,arg){
						
						}
				},
				"buttons":[
					{
						"$type":"Button",
						"caption":"\u786E\u5B9A",
						"listener":{
							"onClick":function(self,arg){
								var criteria = criter.get('criteria');
								var paras = ds.get("parameter");
								if(paras){
									if(paras instanceof dorado.util.Map){
										paras.put("__criteria", criteria);
									}else{
										if(paras instanceof dorado.Entity){
											try{
												paras.set("__criteria", criteria);
											}catch (e) {
												paras.__criteria = criteria;
											}
										}else{
											paras.__criteria = criteria;
										}
									}
								}else{
									paras = $map({"__criteria": criteria});
									ds.set("parameter", paras);
								}
								var tags = grid.get("tags");
								if(tags && tags.indexOf("queryDataGrid")>=0){
									var __dataType = ds.get("dataType.name");
									if(paras instanceof dorado.util.Map && !paras.get("__dataType")){
										paras.put("__dataType", __dataType);
									}
								}
								ds.flushAsync();
								dialog.hide();
							}
						}
					},
					{
						"$type":"Button",
						"caption":"\u5173\u95ED",
						"listener":{
							"onClick":function(self,arg){
									dialog.hide();
								}
						}
					}
				]
			}) ;
			dialog.addChild(criter);
			view.addChild(dialog);
	}
	dialog.show();
};

gdgs.ndp.gridbar.showChart=function(view,gridId ,chartType,xAxis,yAxis){

		if(chartType &&xAxis && yAxis){
			
		}else{
			// if chartType define ,xAxis and yAxis can't null or undefine
			chartType =null;
		}
		var grid = view.get('#'+gridId);
		var ds = grid.get('dataSet')
		var parent = grid.$_parent;
		if(!parent){
			parent=grid.get('parent');
			grid.$_parent=parent;
		}
		if(!parent.$_cardbook){
			 
			var cardbook = new dorado.widget.CardBook({
				'layoutConstraint':{type:"center"}	
			});
			parent.removeChild(grid);
			var gridcontainer = new dorado.widget.Container(
					{'layoutConstraint':{type:"center"}	}
			);
			parent.addChild(cardbook);
			cardbook.addControl(gridcontainer);
			gridcontainer.addChild(grid);
			parent.$_cardbook = cardbook;
			parent.$_grid=gridcontainer;
		}
		
		var list = ds.getData();
		var current = list.current;
		var chartbtn = parent;
		var dataType = ds.get('dataType');
		
		var propertyDefs = null;
		if(dataType instanceof dorado.AggregationDataType){
			 propertyDefs = dataType.get('elementDataType').get('propertyDefs');
		}else if(dataType instanceof dorado.EntityDataType){
			propertyDefs=dataType.get('propertyDefs');
		}
		if(propertyDefs){
				var container =parent.$_chartContainer;
				if(!container){
				var onGetBindingDataHanlder =function(self,arg){
						var x = view.get('#textEditorX'+gridId);
						if(x){
							x.fireEvent('onReady',x);
						}
						var y = view.get('#tagEditorY'+gridId);
						if(x){
							y.fireEvent('onReady',y);
						}
						var dsy = view.get("#dataSet_$_Y"+gridId);
						if(dsy){
							dsy.fireEvent('onReady',dsy);
						}
					};
					grid.addListener("onGetBindingData",onGetBindingDataHanlder);
					container =new dorado.widget.Container(
							{
									id:'$_container1'+gridId,
								   'layoutConstraint':{type:"center"},
									"children":[
									{
										"$type":"ToolBar",
										"items":[
											{
												"$type":"ToolBarLabel",
												"text":"X\u5750\u6807"
											},
											{
												"$type":"TextEditor",
												"id":"textEditorX"+gridId,
												"value": '',
												"listener":{
													"onReady":gdgs.ndp.gridbar.showChart.textEditorXOnReady(propertyDefs,xAxis)
												}
											},{
												"$type":"Separator"
											},
											{
												"$type":"ToolBarLabel",
												"text":"Y\u5750\u6807"
											},
											{
												"$type":"TagEditor",
												"id":"tagEditorY"+gridId,
												"width":"400",
												 "editable":false,
												 "value": yAxis || '',
												"listener":{
													"onReady":gdgs.ndp.gridbar.showChart.textEditorYOnReady(dataType,yAxis)
												},
												"trigger":view.getComponentReference("customDropDown_$_Y"+gridId)
											},{
												"$type":"Separator"
											},
											{
												"$type":"RadioGroup",
												"id":"radioGroup_$_ChartType"+gridId,
												"value": chartType || 'pie',
												"radioButtons":[
														{
															"text":"<img src='"+$url(">dorado/ndp/res/base/icon/pie.png")+"'/>",
															"value":"pie"
														},
														{
															"text":"<img src='"+$url(">dorado/ndp/res/base/icon/bar.png")+"'/>",
															"value":"bar"
														},
														{
															"text":"<img src='"+$url(">dorado/ndp/res/base/icon/line.png")+"'/>",
															"value":"line"
														}
												],
												"listener":{
													"onClick":gdgs.ndp.gridbar.showChart.radiogroupChartTypeClick(gridId,propertyDefs,ds,chartbtn,view)
												}// end listener
											},
											{
												"$type":"ToolBarButton",
												"caption":"\u9AD8\u7EA7\u914D\u7F6E",
												"listener":{
													"onClick":function(self,arg){
														var dialog = view.get('#$_dialogStepPz'+gridId);
														if(!dialog){
															dialog = new dorado.widget.Dialog(gdgs.ndp.gridbar.advanceDialogConfig(view,gridId));
														}
														view.addChild(dialog);
														dialog.show();
													}
												}// listener
											},
											{
												"$type":"Separator"
											}
										],
										"layoutConstraint":{
											"type":"top"
										}
									},
									{
										"$type":"CustomDropDown",
										"id":"customDropDown_$_Y"+gridId,
										"control":{
											"$type":"Container",
											"height": 280,
											"children":[
												{
													"$type":"DataGrid",
													"columns":[
														{
															"$type":"[]"
														},
														{
															"name":"label",
															"property":"label",
															"readOnly":true
														}
													],
													"selectionMode":"multiRows",
													"dataSet":view.getComponentReference("dataSet_$_Y"+gridId),
													"id":"dataGrid_$_Y"+gridId,
													"listener":{
														"onReady":function(self,arg){
															var dropdown = dorado.widget.DropDown.findDropDown(self);
															var editor =dropdown.get('editor');
															var select = editor.$_selectEntity;
															var entityList = self.getBindingData();
															var obj =[];
															if(select){
																select.each(function(o){
																	entityList.each(function(entity){
																		if(o.get('name') == entity.get('name'))
																			obj.push(entity);
																	});
																});
																self.set('selection',obj);
															}
														}
													}
												},
												{
													"$type":"Container",
													"layoutConstraint":{
															"type":"bottom"
														},
													"layout":{
															"$type":"VBox"
														},
													"children":[
														{
															"$type":"Button",
															"caption":"\u786E\u5B9A",
															"layoutConstraint":{
																"align":"center"
															},
															"listener":{
																"onClick":function(self,arg){
																   var dropdown = dorado.widget.DropDown.findDropDown(self);
																   var editor =dropdown.get('editor');
																   var grid = view.get("#dataGrid_$_Y"+gridId);
																   var selectEntity = grid.get('selection');
																   var values ="";
																   
																   if(selectEntity && selectEntity.length>0){
																		selectEntity.each(function(o){
																			values += o.get('label')+",";
																		});
																		editor.$_selectEntity=selectEntity;
																   }
																   var returnValue = values.substring(0, values.lastIndexOf(','));
																   dropdown.close(returnValue);  
											
																}
															}
														}
													]
												}
											]
										}
									},// customdropdown,
									{
										"$type":"DataSet",
										"id":"dataSet_$_Y"+gridId,
										"dataType":"[UnknownMap]",
										"listener":{
											"onReady":function(self,arg){
												var data =[];
												propertyDefs.each(function(o){
													var type = o.get('dataType');
													switch(type.get('name')) {
														case "Integer":
															 
														case "Short":
															 
														case "Long":
														 
														case "Float":
															 
														case "Double":
															 
														case "BigDecimal":
															 
														case "Byte":
															data.push({label:o.get('label'),name:o.get('name')});
															break;
														default:
															break;
													}
												});
												self.setData(data);
											}
										}
									}
								]
							}	
					);// end
					parent.$_chartContainer = container;
					parent.$_cardbook.addControl(container);
				}
				
				
				if(chartType && xAxis && yAxis){
					var type = chartType;
					switch(type){
					   case "bar":
						   type="column";
							var  valuePropertie=yAxis;
							var categoriePropertie=xAxis;
							if(valuePropertie&&""!= valuePropertie &&categoriePropertie&&""!=categoriePropertie){
								
								if(chartbtn.chart){
									container.removeChild(chartbtn.chart);
								}
								var json =null;
								var chart = null;
								if(window.chartConfig){
									json = window.chartConfig[type];
								}
								if(!json){
									gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,xAxis,yAxis,ds,container,chartbtn)
								}else{
									gdgs.ndp.gridbar.createJsonChart(json,xAxis,yAxis,ds,container,chartbtn);
								}
								
							}
						   break;
					   case "pie":
						   
							var  valuePropertie=yAxis;
							var nameProperties=xAxis;
							if(valuePropertie&&""!= valuePropertie &&""!=nameProperties && valuePropertie.indexOf(',') == -1){
							 
								if(chartbtn.chart){
								   container.removeChild(chartbtn.chart);
								}
								var json =null;
								var chart = null;
								if(window.chartConfig){
									json = window.chartConfig[type];
								}
								if(!json){
									gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,xAxis,yAxis,ds,container,chartbtn)
								}else{
									chart = gdgs.ndp.gridbar.createJsonChart(json,xAxis,yAxis,ds,container,chartbtn);
								}
							}else{
								dorado.widget.NotifyTipManager.notify('\u997C\u56FE\u53EA\u80FD\u663E\u793A\u4E00\u5217\u6570\u636E');
							}
						   break;
					   case "line":
							var  valuePropertie=yAxis;
							var categoriePropertie=xAxis;
							if(valuePropertie&&""!= valuePropertie &&categoriePropertie&&""!=categoriePropertie){
								var realvalueProperty=valuePropertie;
							 
								 
								if(chartbtn.chart){
									container.removeChild(chartbtn.chart);
								}
								 
								var json =null;
								var chart = null;
								if(window.chartConfig){
									json = window.chartConfig[type];
								}
								if(!json){
									gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,xAxis,yAxis,ds,container,chartbtn)
								}else{
									chart = gdgs.ndp.gridbar.createJsonChart(json,xAxis,yAxis,ds,container,chartbtn);
								}
							}
						   break;
					  
					}
				}else{
				
					if(!chartbtn.chart){
						var categoriePropertie,valuePropertie;
						for(var i=0,len=propertyDefs.size;i<len;i++){
							var type = propertyDefs.items[i].get('dataType').get('name');
							switch(type) {
														 
								case "String":
									categoriePropertie =propertyDefs.items[i].get('name');
									break;
								case "Integer":
															 
								case "Short":
									 
								case "Long":
								 
								case "Float":
									 
								case "Double":
									 
								case "BigDecimal":
									 
								case "Byte":
									valuePropertie =propertyDefs.items[i].get('name');
									break;
								default:
									break;
							}
							 if(categoriePropertie && valuePropertie) break;
						}
							if(valuePropertie&&""!= valuePropertie &&categoriePropertie&&""!=categoriePropertie){
								var type ="column";
								if(chartbtn.chart){
									container.removeChild(chartbtn.chart);
								}
								var json =null;
								var chart = null;
								if(window.chartConfig){
									json = window.chartConfig[type];
								}
								if(!json){
									gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,categoriePropertie,valuePropertie,ds,container,chartbtn)
								}else{
									gdgs.ndp.gridbar.createJsonChart(json,categoriePropertie,valuePropertie,ds,container,chartbtn);
								}
							}
					}
					
					 
				}
				parent.$_cardbook.set('currentControl',container);
				
		}
		 
	}
gdgs.ndp.gridbar.createJsonChart =function(json,xAxis,yAxis,ds,container,chartbtn){
	var chart = json.chart;
	var legend = json.legend;
	var title = json.title;
	var plotOptions = json.plotOptions;
	var tooltip = json.tooltip;
	var xAxisjson = json.xAxis;
	var yAxisjson = json.yAxis;
	var dataList = ds.getData();
	var chart = new dorado.widget.highcharts.CustomerChart({
		'dataSet':ds,
		'chartTypeDataJSON':chart,
		'legendDataJSON':legend,
		'titleDataJSON':title,
		'specialDataJSON':plotOptions,
		'toolTipDataJSON':tooltip,
		'xDataJSON':xAxisjson,
		'yDataJSON':yAxisjson,
		"xAxis":xAxis,
		"yAxis":yAxis,
		"categories":xAxis
	});
	chartbtn.chart=chart;
	container.addChild(chart);
	chart.doReLoad();
}
gdgs.ndp.gridbar.showChart.getDisplayFormatText= function(entity, propertyDef){
	function toText(value, propertyDef, displayFormat) {
		var text;
		if (propertyDef && displayFormat) {
			var dataType = propertyDef.get("dataType");
			text = (dataType || dorado.$String).toText(value, displayFormat);
			if (text && propertyDef._mapping)
				text = propertyDef.getMappedValue(text) || "";
		} else {
			text = dorado.$String.toText(value);
		}
		return text;
	};
	var value = entity.get(propertyDef.get("name"));
	var dataType = propertyDef.get("dataType");
	var userData =propertyDef.get("userData");
	var displayFormat =  null;
	if(userData){
		displayFormat = userData.displayFormat;
		if(value &&displayFormat){
			if(displayFormat.indexOf("\u4E07") > -1){
				value = dorado.util.Common.parseFloat(value)/10000;
			}else if(displayFormat.indexOf("\u4EBF") > -1){
				value = dorado.util.Common.parseFloat(value)/100000000;
			}else if(displayFormat == "0.00%"){
				value = value * 100;
			}//others
		}
	}
	
	return toText(value, propertyDef, displayFormat);
}
	gdgs.ndp.gridbar.showChart.textEditorXOnReady=function(propertyDefs,xAxis){
		return function(self,arg){
										var data =[];
										propertyDefs.each(function(o){
											var type = o.get('dataType');
											switch(type.get('name')) {
												 
												case "String":
													data.push({key:o.get('name'),value:o.get('label')});
													break;
												default:
													break;
											}
										});
										self.set('mapping',data);
										self.set("trigger",new dorado.widget.AutoMappingDropDown(data));
										if(xAxis){
											self.set('value',xAxis);
										}
									}
	}
	gdgs.ndp.gridbar.showChart.textEditorYOnReady=function(dataType,yAxis){
		return function(self,arg){
										if(yAxis){
											
											var dtype =null;
											if(dataType instanceof dorado.AggregationDataType){
												dtype = dataType.get('elementDataType');
											}else if(dataType instanceof dorado.EntityDataType){
												dtype=dataType;
											}
											var yvalues = yAxis.split(',');
											var labels ="";
											var selectEntity =[];
											for(var i=0,len=yvalues.length;i<len;i++){
												var protydef =dtype.getPropertyDef(yvalues[i]);
												labels +=protydef.get('label')+",";
												selectEntity.push($map({name:protydef.get('name'),label:protydef.get('label')}))
											}
											self.set('value',labels.substring(0, labels.lastIndexOf(',')));
											self.$_selectEntity = selectEntity;
										} 
									}
	}
	gdgs.ndp.gridbar.showChart.loadChartConfig=function(type,callback,xAxis,yAxis,ds,container,chartbtn){
		$.ajax({
			url:$url('>dorado/ndp/res/base/highchart/defaultConfig/')+type+'/'+type+'.json?'+new Date().getTime,
			type:'get',
			dataType:'json',
			timeout:100000,
			error:function(json){
				alert('Error loading json document'+json);
			},
			success:function(json){
				if(!window.chartConfig) window.chartConfig={};
				if(!window.chartConfig[type]) chartConfig[type]=json;
				if(callback){
					 callback(json,xAxis,yAxis,ds,container,chartbtn);
				}
			}
		});
	}
	gdgs.ndp.gridbar.showChart.radiogroupChartTypeClick =function(gridId,propertyDefs,ds,chartbtn,view){
	
		return function(self,arg){// onValueChange
			var container =view.get('#$_container1'+gridId);
									var radio = self;
									var valuePropertie=view.get('#tagEditorY'+gridId+'.text'),categoriePropertie=view.get('#textEditorX'+gridId+'.value');
									var nameProperties=view.get('#textEditorX'+gridId+'.value');
									var categoriePropertie,valuePropertie;
									for(var i=0,len=propertyDefs.size;i<len;i++){
										var type = propertyDefs.items[i].get('dataType').get('name');
										switch(type) {					 
											case "String":
												if(!categoriePropertie)
												  categoriePropertie =propertyDefs.items[i].get('name');
												if(!nameProperties)
												  nameProperties =propertyDefs.items[i].get('name');
												break;
											case "Integer":
																		 
											case "Short":
												 
											case "Long":
											 
											case "Float":
												 
											case "Double":
												 
											case "BigDecimal":
												 
											case "Byte":
												if(!valuePropertie)
													valuePropertie =propertyDefs.items[i].get('name');
												break;
											default:
												break;
										}
										if(categoriePropertie&&nameProperties&&valuePropertie){
											break;
										}
									}// end for
									var type = radio.get('value');
									var tagEditor =view.get('#tagEditorY'+gridId);
									switch(type){
									   case "bar":
										   	type ="column";
											if(valuePropertie&&""!= valuePropertie &&categoriePropertie&&""!=categoriePropertie){
												var realvalueProperty="";
											 
												var $_selectEntity = tagEditor.$_selectEntity;
												if($_selectEntity){
													$_selectEntity.each(function(o){
														realvalueProperty+=o.get("name")+",";
													});
												}
												if(realvalueProperty.indexOf(',')>-1){
													realvalueProperty=realvalueProperty.substring(0,realvalueProperty.length-1);
												}
												if("" == realvalueProperty){
													realvalueProperty =valuePropertie;
												}
												if(chartbtn.chart){
													container.removeChild(chartbtn.chart);
												}
												var json =null;
												var chart = null;
												if(window.chartConfig){
													json = window.chartConfig[type];
												}
												if(!json){
													gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,categoriePropertie,valuePropertie,ds,container,chartbtn)
												}else{
													gdgs.ndp.gridbar.createJsonChart(json,categoriePropertie,valuePropertie,ds,container,chartbtn);
												}
											}
										   break;
									   case "pie":
										   
											
											if(valuePropertie&&""!= valuePropertie &&""!=nameProperties && valuePropertie.indexOf(',') == -1){
											 
												var $_selectEntity = tagEditor.$_selectEntity;
												if($_selectEntity){
													valuePropertie =$_selectEntity[0].get('name');
												}
												if(chartbtn.chart){
													container.removeChild(chartbtn.chart);
												}
												var json =null;
												var chart = null;
												if(window.chartConfig){
													json = window.chartConfig[type];
												}
												if(!json){
													gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,nameProperties,valuePropertie,ds,container,chartbtn)
												}else{
													gdgs.ndp.gridbar.createJsonChart(json,nameProperties,valuePropertie,ds,container,chartbtn);
												}
											}else{
												dorado.widget.NotifyTipManager.notify('\u997C\u56FE\u53EA\u80FD\u663E\u793A\u4E00\u5217\u6570\u636E');
											}
										   break;
									   case "line":
											if(valuePropertie&&""!= valuePropertie &&categoriePropertie&&""!=categoriePropertie){
												var realvalueProperty="";
											 
												var $_selectEntity = tagEditor.$_selectEntity;
												if($_selectEntity){
													$_selectEntity.each(function(o){
														realvalueProperty+=o.get("name")+",";
													});
												}
												if(realvalueProperty.indexOf(',')>-1){
													realvalueProperty=realvalueProperty.substring(0,realvalueProperty.length-1);
												}
												if("" == realvalueProperty){
													realvalueProperty =valuePropertie;
												}
												if(chartbtn.chart){
													container.removeChild(chartbtn.chart);
												}
												var json =null;
												var chart = null;
												if(window.chartConfig){
													json = window.chartConfig[type];
												}
												if(!json){
													gdgs.ndp.gridbar.showChart.loadChartConfig(type,gdgs.ndp.gridbar.createJsonChart,categoriePropertie,valuePropertie,ds,container,chartbtn)
												}else{
													gdgs.ndp.gridbar.createJsonChart(json,categoriePropertie,valuePropertie,ds,container,chartbtn);
												}
											}
										   break;
									  
									}
								}
	}
	

gdgs.ndp.gridbar.showForm=function(view,gridId){
	 
    var grid = view.get('#' + gridId);
    var ds = grid.get('dataSet')
    var parent = grid.$_parent;
	if(!parent){
		parent=grid.get('parent');
		grid.$_parent=parent;
	}
    if(!parent.$_cardbook){
    	var cardbook = new dorado.widget.CardBook({
			'layoutConstraint':{type:"center"}	
		});
		parent.removeChild(grid);
		var container = new dorado.widget.Container(
				{'layoutConstraint':{type:"center"}	}
		);
		parent.addChild(cardbook);
		container.addChild(grid);
		cardbook.addControl(container);
		parent.$_cardbook = cardbook;
		parent.$_grid=container;
	}
	var formbtn=parent;
	var list =ds.getData();
	var dataType = ds.get('dataType');
	var propertyDefs = null;
	if(dataType instanceof dorado.AggregationDataType){
		 propertyDefs = dataType.get('elementDataType').get('propertyDefs');
	}else if(dataType instanceof dorado.EntityDataType){
		propertyDefs=dataType.get('propertyDefs');
	}
	if(propertyDefs){
		 
		
		var container =formbtn.$_formContainer;
		if(!container){
			container =new dorado.widget.Container({
				layoutConstraint:{type:"center"},
				contentOverflowY:'auto'
			});
			
			var detailForm=	new dorado.widget.AutoForm({
				cols:"*,*",
				labelAlign:"right",
				dataSet:ds,
	            layoutConstraint:{type:"center"},
				labelWidth:260,
				'readOnly':grid.get('readOnly')
				
			});	
			 
			propertyDefs.each(function(property){
				detailForm.addElement({
				property:property.get('name'),
				label:property.get('label'),
				layoutConstraint:{colSpan:1}
				});
			});	
			container.addChild(detailForm);
			var toolBar = new dorado.widget.ToolBar({
				layoutConstraint: {
					type: "top"
				}
			});
			var btnPrev =new dorado.widget.toolbar.Button({
				caption:'\u524D\u4E00\u4E2A',
				listener:{
					onClick:function(){
						var grid = formbtn.$_grid;
							var list = ds.getData();
						list.previous();
					}
				}
			});
			var btnback =new dorado.widget.toolbar.Button({
				caption:'\u4E0B\u4E00\u4E2A',
				listener:{
					onClick:function(){
						var grid = formbtn.$_grid;
						 
						var list = ds.getData();
						list.next();
					}
				}
			});
			toolBar.addItem(btnPrev);
			toolBar.addItem(btnback);
			container.addChild(toolBar);
			parent.$_cardbook.addControl(container);
			formbtn.$_formContainer=container;
		}
		
		parent.$_formContainer=container;
		parent.$_cardbook.set('currentControl',container);
		
	}
		
}

gdgs.ndp.gridbar.showGrid=function(view,gridId){
	var grid =view.get('#'+gridId);
	var parent = grid.$_parent;
	if(!parent){
		parent =grid.get('parent');
		grid.$_parent = parent;
	}
	if(parent.$_cardbook){
		parent.$_cardbook.set('currentControl',parent.$_grid);
	}
	
}